package logic

import (
	"context"
	"guar/model/mysql"

	"guar/guarrpc/guarrpc"
	"guar/guarrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *guarrpc.ListRequest) (*guarrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var shops []mysql.Shop
	mysql.DB.Debug().Find(&shops)

	var shopList []*guarrpc.ShopList

	for _, shop := range shops {

		list := guarrpc.ShopList{
			ShopNo: shop.ShopNo,
			Desc:   shop.Desc,
			Price:  float32(shop.Price),
			UserId: int64(shop.UserId),
		}
		shopList = append(shopList, &list)
	}

	return &guarrpc.ListResponse{
		List: shopList,
	}, nil
}
